#!/usr/bin/env python

# latex2utf_web.py
# Copyright (C) 2008 Alexander Rodin                                        
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import cgi
from latex2utf import latex2utf

form = cgi.FieldStorage()
if form.has_key('latex'):
    latex = form['latex']
    utf = latex2utf(latex.value)
else:
    latex = ''
    utf = ''

print 'Content-Type: text/html'
print ''
print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
print '<head>'
print '<meta http-equiv="content-type" content="text/html; charset=UTF-8">'
print '<title>LaTeX 2 UTF converter</title>'
print '</head>'
print '<body>'
print '<center>'
print '<form name="latex2utf_input" method="GET">'
print 'Enter the formula (see list of available commands <a href="http://code.google.com/p/latex2utf/wiki/SupportedCommands">here</a>):<br>'
print '<input type="text" size="64" name="latex" value="' + latex.value.replace('"', '&#34;') + '"/><br>'
print '<input type="submit"/>'
print '</form>'
print 'Processed formula:<br>'
print '<input type="text" size="64" value="' + utf.replace('"', '&#34;') + '"/>'
print '<hr>'
print 'Copyright &copy; <a href="http://code.google.com/p/latex2utf/">LaTeX 2 UTF project</a>'
print '</center>'
print '</body>'
print '</html>'

# vim: set tabstop=4 softtabstop=4 shiftwidth=4 expandtab :

